/**
 * 
 */
package springdata_CrudRepository.controller;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import springdata_CrudRepository.domain.User;
import springdata_CrudRepository.pager.PageModel;
import springdata_CrudRepository.service.UserService;

/**
 * @author 罗老师【Long】
 * Version:1.0
 * 备注：本套课程提供全部源码+笔记+相关开发工具+答疑服务
 */
@Controller
public class UserController {
	
	@Resource
	private UserService userService;

	 
	 //进行分页查询
	 @RequestMapping("/pager")
	 public String pager(Model model,PageModel pageModel) {
		 
		Page<User> page = userService.findUserByPage(pageModel.getPageIndex() - 1);
		System.out.println("请求的第几页："+page.getNumber());
		System.out.println("当前页有多少个元素:"+page.getNumberOfElements());
		 System.out.println("总共有多少条数据:"+page.getTotalElements());
		 System.out.println("总页数："+page.getTotalPages());
		 
		 pageModel.setRecordCount(page.getTotalElements());
	     model.addAttribute("pageModel", pageModel);
	     
		 List<User> users = page.getContent();
		 model.addAttribute("users", users);
		 return "list";
	 }
}
